import { PageContainer } from '@ant-design/pro-layout';
import { Table,Card,Button,Modal, Input } from 'antd';
import {SearchOutlined,PlusOutlined} from '@ant-design/icons'
import {UseSearch,UseTable} from '../../../components'
import React from 'react';
import moment from 'moment';
import InnovationProjectController from '@/services/InnovationProject/InnovationProjectController';
import { getStr } from '@/components/function';
import EvaluationSubmit from './EvaluationSubmit'
import Detail from '../detail'
import InnovationEvaluationController from '@/services/InnovationProject/InnovationEvaluationController';
class FirstEvaluation extends React.Component {
    constructor(props) {
        super(props);
        this.state = { 
            dataSource:[],
            freshen:false,
            userInfo:JSON.parse(sessionStorage.getItem("userInfo"))
         };
    }
    showNewProject=()=>{
        this.setState({
            visibleNewProject:true
        })
    }
    freshen=()=>{
        this.setState({freshen:!this.state.freshen})
    }
    handleSearch=(query)=>{
        this.setState({query})
        this.freshen()

    }
    reset=()=>{
        this.setState({query:{}})
        this.freshen()

    }
    getList=(query)=>{
        let {userInfo} = this.state
        if(userInfo.roleName.includes("市级部门负责人")){
            query.cityDepartmentName = userInfo.cityDepartmentName
        }
        else if(userInfo.roleName.includes("省级部门负责人")){
            query.provinceDepartmentName = userInfo.provinceDepartmentName
        }
        else{
            query.provinceDepartmentName =""
        }
        return InnovationEvaluationController.getFirstEvaluationList(query)
    }
    onCancel=()=>{
        this.setState({visibleNewProject:false,visibleResult:false})
        this.freshen()
    }
    toDetail=(rowData)=>{
        this.setState({
            rowData,
            visibleDetail:true
        })
    }
    toResult=(rowData)=>{
        this.setState({
            rowData,
            visibleResult:true
        })
    }
    onRef=(ref)=>{
        this.setState({
            modal:ref
        })
    }
    submit=()=>{
        this.state.modal.submit()
    }
    render() {
        const {rowData,visibleNewProject,freshen,visibleDetail,query,visibleResult}=this.state
        const columns=[

            {title:'项目名称',dataIndex:'projectName',align:'center'},
            {title:'项目类别',dataIndex:'projectType',align:'center'},
            {title:'项目负责人',dataIndex:'projectLeaderName',align:'center'},
            {title:'预算总额',dataIndex:'budgetTotal',align:'center'},
            {title:'实施方案',dataIndex:'implementationPlan',align:'center',render:text=>getStr(text)},
            {title:'项目要点',dataIndex:'projectPoint',align:'center',render:text=>getStr(text)},
            {title:'研究方向',dataIndex:'researchDirection',align:'center',render:text=>getStr(text)},
            {title:'申报原因',dataIndex:'approvalReasons',align:'center',render:text=>getStr(text)},
            {title:'申报时间',dataIndex:'createdAt',align:'center',render:text=>moment(text).format("YYYY-MM-DD")},
            {title:'审核步骤',dataIndex:'applyReviewStep',align:'center'},
            {title:'审核结果',dataIndex:'applyReviewResult',align:'center'},
            {title:'操作',align:'center',render:(text,rowData)=><div>
                <Button onClick={this.toDetail.bind(this,rowData)} type={'primary'}>查看详情</Button>
                <Button onClick={this.toResult.bind(this,rowData)} type={'primary'}>成果评定</Button>
                </div>},
        ]
        const buttonStyle={margin:5}
        const searchItem=[
            {name:'负责人姓名',keyName:'leaderUserName',valueType:'text'},
            {name:'项目名称',keyName:'projectName',valueType:'text'},
        ]
        return (
            <div>
                <Card>
                <UseSearch searchItem={searchItem} handleSearch={this.handleSearch} reset={this.reset}
                    />  
                </Card>
                <Card>
                    <UseTable columns={columns} getData={this.getList} bordered rowKey={'projectCode'} refresh={freshen} query={query}/>
                </Card>

                <Modal
                visible={visibleDetail}
                title={'项目详情'}
                onCancel={()=>this.setState({visibleDetail:false})}
                footer={false}
                width={"80%"}
                >
                    {visibleDetail&&<Detail rowData={rowData}/>}
                </Modal>
                <Modal
                visible={visibleResult}
                title={'成果评定'}
                onCancel={()=>this.setState({visibleResult:false})}
                onOk={this.submit}
                width={'60%'}
                >
                    {visibleResult&&<EvaluationSubmit rowData={rowData} onCancel={this.onCancel} resultEvaluationStep='初评' onRef={this.onRef} />}
                </Modal>
            </div>
        );
    }
}

export default FirstEvaluation;